import type { PageFilter } from '@/types/visual-app'

export interface PageStyleParams {
  pageBgColor?: string
  pageBgImg?: string
  fitMode?: string
  filter?: PageFilter
  width?: number | string
  height?: number | string
}

/**
 * 根据页面参数生成 style 对象
 */
export function getPageStyle(params: PageStyleParams): Record<string, string> {
  const { pageBgColor, pageBgImg, fitMode, filter, width, height } = params
  const style: Record<string, string> = {}

  // 背景色
  if (pageBgColor) style.backgroundColor = pageBgColor

  // 背景图片
  if (pageBgImg) {
    style.backgroundImage = `url(${pageBgImg})`
    style.backgroundRepeat = 'no-repeat'
    style.backgroundPosition = 'center'
    style.backgroundSize = fitMode === 'cover'
      ? 'cover'
      : fitMode === 'contain'
        ? 'contain'
        : fitMode === 'stretch'
          ? '100% 100%'
          : 'auto'
  }

  // 滤镜
  if (filter) {
    style.filter = [
      `hue-rotate(${filter.hue || 0}deg)`,
      `saturate(${filter.saturate || 100}%)`,
      `contrast(${filter.contrast || 100}%)`,
      `brightness(${filter.brightness || 100}%)`,
      `opacity(${(filter.opacity ?? 100) / 100})`
    ].join(' ')
  }

  // 画布宽高
  if (width !== undefined) style.width = typeof width === 'number' ? `${width}px` : width
  if (height !== undefined) style.height = typeof height === 'number' ? `${height}px` : height

  return style
} 